// const dayjs = require('dayjs');
// const axios = require('axios');
const url = require('url');
function s(t, e, r, n, i, o, s) {
  return a((e & r) | (~e & n), t, e, i, o, s);
}
function o(t, e) {
  const r = (65535 & t) + (65535 & e);
  return (((t >> 16) + (e >> 16) + (r >> 16)) << 16) | (65535 & r);
}
function a(t, e, r, n, i, a) {
  let s, u;
  return o(((s = o(o(e, t), o(n, a))) << (u = i)) | (s >>> (32 - u)), r);
}

function u(t, e, r, n, i, o, s) {
  return a((e & n) | (r & ~n), t, e, i, o, s);
}
function c(t, e, r, n, i, o, s) {
  return a(e ^ r ^ n, t, e, i, o, s);
}
function f(t, e, r, n, i, o, s) {
  return a(r ^ (e | ~n), t, e, i, o, s);
}
function h(t, e) {
  let r, n, i, a, h;
  (t[e >> 5] |= 128 << e % 32), (t[14 + (((e + 64) >>> 9) << 4)] = e);
  let l = 1732584193,
    d = -271733879,
    p = -1732584194,
    m = 271733878;
  for (r = 0; r < t.length; r += 16) {
    (n = l),
      (i = d),
      (a = p),
      (h = m),
      (l = s(l, d, p, m, t[r], 7, -680876936)),
      (m = s(m, l, d, p, t[r + 1], 12, -389564586)),
      (p = s(p, m, l, d, t[r + 2], 17, 606105819)),
      (d = s(d, p, m, l, t[r + 3], 22, -1044525330)),
      (l = s(l, d, p, m, t[r + 4], 7, -176418897)),
      (m = s(m, l, d, p, t[r + 5], 12, 1200080426)),
      (p = s(p, m, l, d, t[r + 6], 17, -1473231341)),
      (d = s(d, p, m, l, t[r + 7], 22, -45705983)),
      (l = s(l, d, p, m, t[r + 8], 7, 1770035416)),
      (m = s(m, l, d, p, t[r + 9], 12, -1958414417)),
      (p = s(p, m, l, d, t[r + 10], 17, -42063)),
      (d = s(d, p, m, l, t[r + 11], 22, -1990404162)),
      (l = s(l, d, p, m, t[r + 12], 7, 1804603682)),
      (m = s(m, l, d, p, t[r + 13], 12, -40341101)),
      (p = s(p, m, l, d, t[r + 14], 17, -1502002290)),
      (l = u(
        l,
        (d = s(d, p, m, l, t[r + 15], 22, 1236535329)),
        p,
        m,
        t[r + 1],
        5,
        -165796510
      )),
      (m = u(m, l, d, p, t[r + 6], 9, -1069501632)),
      (p = u(p, m, l, d, t[r + 11], 14, 643717713)),
      (d = u(d, p, m, l, t[r], 20, -373897302)),
      (l = u(l, d, p, m, t[r + 5], 5, -701558691)),
      (m = u(m, l, d, p, t[r + 10], 9, 38016083)),
      (p = u(p, m, l, d, t[r + 15], 14, -660478335)),
      (d = u(d, p, m, l, t[r + 4], 20, -405537848)),
      (l = u(l, d, p, m, t[r + 9], 5, 568446438)),
      (m = u(m, l, d, p, t[r + 14], 9, -1019803690)),
      (p = u(p, m, l, d, t[r + 3], 14, -187363961)),
      (d = u(d, p, m, l, t[r + 8], 20, 1163531501)),
      (l = u(l, d, p, m, t[r + 13], 5, -1444681467)),
      (m = u(m, l, d, p, t[r + 2], 9, -51403784)),
      (p = u(p, m, l, d, t[r + 7], 14, 1735328473)),
      (l = c(
        l,
        (d = u(d, p, m, l, t[r + 12], 20, -1926607734)),
        p,
        m,
        t[r + 5],
        4,
        -378558
      )),
      (m = c(m, l, d, p, t[r + 8], 11, -2022574463)),
      (p = c(p, m, l, d, t[r + 11], 16, 1839030562)),
      (d = c(d, p, m, l, t[r + 14], 23, -35309556)),
      (l = c(l, d, p, m, t[r + 1], 4, -1530992060)),
      (m = c(m, l, d, p, t[r + 4], 11, 1272893353)),
      (p = c(p, m, l, d, t[r + 7], 16, -155497632)),
      (d = c(d, p, m, l, t[r + 10], 23, -1094730640)),
      (l = c(l, d, p, m, t[r + 13], 4, 681279174)),
      (m = c(m, l, d, p, t[r], 11, -358537222)),
      (p = c(p, m, l, d, t[r + 3], 16, -722521979)),
      (d = c(d, p, m, l, t[r + 6], 23, 76029189)),
      (l = c(l, d, p, m, t[r + 9], 4, -640364487)),
      (m = c(m, l, d, p, t[r + 12], 11, -421815835)),
      (p = c(p, m, l, d, t[r + 15], 16, 530742520)),
      (l = f(
        l,
        (d = c(d, p, m, l, t[r + 2], 23, -995338651)),
        p,
        m,
        t[r],
        6,
        -198630844
      )),
      (m = f(m, l, d, p, t[r + 7], 10, 1126891415)),
      (p = f(p, m, l, d, t[r + 14], 15, -1416354905)),
      (d = f(d, p, m, l, t[r + 5], 21, -57434055)),
      (l = f(l, d, p, m, t[r + 12], 6, 1700485571)),
      (m = f(m, l, d, p, t[r + 3], 10, -1894986606)),
      (p = f(p, m, l, d, t[r + 10], 15, -1051523)),
      (d = f(d, p, m, l, t[r + 1], 21, -2054922799)),
      (l = f(l, d, p, m, t[r + 8], 6, 1873313359)),
      (m = f(m, l, d, p, t[r + 15], 10, -30611744)),
      (p = f(p, m, l, d, t[r + 6], 15, -1560198380)),
      (d = f(d, p, m, l, t[r + 13], 21, 1309151649)),
      (l = f(l, d, p, m, t[r + 4], 6, -145523070)),
      (m = f(m, l, d, p, t[r + 11], 10, -1120210379)),
      (p = f(p, m, l, d, t[r + 2], 15, 718787259)),
      (d = f(d, p, m, l, t[r + 9], 21, -343485551)),
      (l = o(l, n)),
      (d = o(d, i)),
      (p = o(p, a)),
      (m = o(m, h));
  }
  return [l, d, p, m];
}
function l(t) {
  let e,
    r = '',
    n = 32 * t.length;
  for (e = 0; e < n; e += 8) {
    r += String.fromCharCode((t[e >> 5] >>> e % 32) & 255);
  }
  return r;
}
function d(t) {
  let e,
    r = [];
  for (r[(t.length >> 2) - 1] = void 0, e = 0; e < r.length; e += 1) r[e] = 0;
  const n = 8 * t.length;
  for (e = 0; e < n; e += 8) r[e >> 5] |= (255 & t.charCodeAt(e / 8)) << e % 32;
  return r;
}
function p(t) {
  let e,
    r,
    n = '0123456789abcdef',
    i = '';
  for (r = 0; r < t.length; r += 1) {
    (e = t.charCodeAt(r)), (i += n.charAt((e >>> 4) & 15) + n.charAt(15 & e));
  }
  return i;
}
function m(t) {
  return unescape(encodeURIComponent(t));
}
function v(t) {
  return (function (t) {
    return l(h(d(t), 8 * t.length));
  })(m(t));
}
function y(t, e) {
  return (function (t, e) {
    let r,
      n,
      i = d(t),
      o = [],
      a = [];
    for (
      o[15] = a[15] = void 0, i.length > 16 && (i = h(i, 8 * t.length)), r = 0;
      r < 16;
      r += 1
    ) {
      (o[r] = 909522486 ^ i[r]), (a[r] = 1549556828 ^ i[r]);
    }
    return (n = h(o.concat(d(e)), 512 + 8 * e.length)), l(h(a.concat(n), 640));
  })(m(t), m(e));
}
function g(t, e, r) {
  return e ? (r ? y(e, t) : p(y(e, t))) : r ? v(t) : p(v(t));
}

function getUuid(t, e) {
  const r =
      '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(
        ''
      ),
    n = [];
  if (((e = e || r.length), t)) {
    for (let i = 0; i < t; i++) n[i] = r[0 | (Math.random() * e)];
  } else {
    let o = null;
    (n[8] = n[13] = n[18] = n[23] = '-'), (n[14] = '4');
    for (let a = 0; a < 36; a++) {
      n[a] ||
        ((o = 0 | (16 * Math.random())), (n[a] = r[a == 19 ? (3 & o) | 8 : o]));
    }
  }
  return n.join('');
}
function currentY(t) {
  const e = {
      appkey: 'sqjDmXVd5LNYf9r4',
      web_site: (t && t.web_site ? t.web_site : '') || 'wenjuan_web',
      timestamp: new Date().getTime(),
    },
    r = t || {};
  Object.assign(r, e);
  const n = Object.keys(r).sort(),
    i = [];
  n.forEach(function (t) {
    ['secret', '__FORMDATA__'].includes(t) || i.push(r[t]);
  });
  return g(i.join('') + 'rltfin41xhvwjgyd75s8aq2oebm0369u');
}
module.exports = (timestr, timestamp, sendUrl) => {
  const newUrl = url.parse(sendUrl);
  const data = {
    appkey: 'sqjDmXVd5LNYf9r4',
    finish_status: '1',
    idy_uuid: g(getUuid()),
    project_version: 1,
    question_captcha_map_str: '{}',
    question_ids_skipped_by_time: '{}',
    timestamp,
    timestr,
    total_answers_str:
      '{"657ab65ca0db0de6bb0dc4fa":["657ab65ca0db0de6bb0dc4f6"],"657ab65ca0db0de6bb0dc4fb":["657ab65ca0db0de6bb0dc4f8"]}',
    web_site: 'wenjuan_web',
    wx_user_info_str: '{}',
    auto_submit_post: false,
  };
  data.signature = currentY(data);
  return {
    url: `https://www.wenjuan.com/api/rspd${newUrl.pathname}`,
    request_headers: {
      'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
      Host: 'www.wenjuan.com',
      Referer: sendUrl,
      'X-Wj-Origin-Survey-Url': sendUrl,
    },
    submit_data: data,
  };
};
